package com.nand.module.function.adapter;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.nand.module.function.R;
import com.nand.module.function.bean.EpairListBean;
import com.nand.module.function.bean.IqcDetailsBean;
import com.nand.module.function.bean.ReviewListBean;

import java.util.ArrayList;
import java.util.List;

/**
 * created by 86185
 * on 2020/1/10
 */

public class ReviewlistAdapter extends RecyclerView.Adapter<ReviewlistAdapter.ViewHolder> implements View.OnClickListener {
    private Context mContext;
    private List<IqcDetailsBean.DataListBean.LogDetailBean> mList = new ArrayList<>();

    private ReviewlistAdapter.OnItemClickListener mOnItemClickListener = null;

    public ReviewlistAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setData(List<IqcDetailsBean.DataListBean.LogDetailBean> data) {
        this.mList = data;
        notifyDataSetChanged();
    }


    @Override
    public ReviewlistAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View layout = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_review, viewGroup, false);
        layout.setOnClickListener(this);
        return new ReviewlistAdapter.ViewHolder(layout);
    }

    @Override
    public void onBindViewHolder(final ReviewlistAdapter.ViewHolder viewHolder, final int position) {
        viewHolder.itemView.setTag(position);
        final IqcDetailsBean.DataListBean.LogDetailBean bean = mList.get(position);
        int state = bean.getState();
        switch (state){
            case 0:
                viewHolder.mTextview1.setText("新增：");
                break;
            case 1:
                viewHolder.mTextview1.setText("工艺评审：");
                break;
            case 2:
                viewHolder.mTextview1.setText("生产评审：");

                break;
            case 3:
                viewHolder.mTextview1.setText("研发评审：");
                break;
            case 4:
                viewHolder.mTextview1.setText("项目总工评审：");
                break;
            case 5:
                viewHolder.mTextview1.setText("质量总监评审：");
                break;
        }
viewHolder.mTextview2.setText(bean.getIqcNgContent());
viewHolder.mTextview3.setText(bean.getCreatedTime());

        viewHolder.mTextview2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mOnItemClickListener!=null){
                    mOnItemClickListener.onXxClick(position,bean.getIqcNgContent(),viewHolder.mTextview2);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        if (mList != null)
            return mList.size();
        return 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView mTextview1, mTextview2, mTextview3;

        public ViewHolder(View itemView) {
            super(itemView);
            mTextview1 = itemView.findViewById(R.id.tv1);
            mTextview2 = itemView.findViewById(R.id.tv2);
            mTextview3 = itemView.findViewById(R.id.tv3);
        }

    }
    //两次点击按钮之间的间隔，目前为1000ms
    private static final int MIN_CLICK_DELAY_TIME = 1000;
    private long lastClickTime;
    public static interface OnItemClickListener {

        void onItemClick(View view, int position);
        void onXxClick(int position, String context, TextView a);
    }

    @Override
    public void onClick(View v) {
        if (mOnItemClickListener != null) {
            long curClickTime = System.currentTimeMillis();
            if ((curClickTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) {
                lastClickTime = curClickTime;
                //注意这里使用getTag方法获取position
                mOnItemClickListener.onItemClick(v, (int) v.getTag());
            }
        }
    }

    public void setOnItemClickListener(ReviewlistAdapter.OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
}

